#include "studentc.h"


double Student::Average() const
{
    if (scores.size() > 0)
        return scores.sum() / scores.size();
    else
        return 0;
}
const std::string & Student::Name() const
{
    return name;
}
double & Student::operator[](int i)
{
    return scores[i];
}
double Student::operator[](int i) const
{
    return scores[i];
}

// friend
std::istream & operator>>(std::istream & is, Student & stu)
{
    is >> stu.name;
    return is;
}
std::istream & getline(std::istream & is, Student & stu)
{
    getline(is, stu.name); // string 的友元函数
    return is;
}
std::ostream & operator<<(std::ostream & os, const Student & stu)
{
    os << stu.name << ": ";
    stu.arr_out(os);

    return os;
}

std::ostream & Student::arr_out(std::ostream & os) const
{
    int lim = scores.size();
    for (int i = 0; i < lim; ++i)
    {
        os << scores[i] << " ";
    }
    os << std::endl;

    return os;
}